package org.mathig.poker.hand;

import java.util.ArrayList;
import java.util.List;

import org.mathig.poker.Card;
import org.mathig.poker.Rank;

/**
 * Super class of Pair, Three of a kind, Four of a kind.
 * 
 * @author mathig
 */
public abstract class ManyOfAKind extends AbstractHand {

	protected List<Card> manyCards = new ArrayList<Card>();

	protected List<Card> otherCards = new ArrayList<Card>();

	public ManyOfAKind(List<Card> manyOfAKind, List<Card> kickers) {
		this.manyCards = manyOfAKind;
		this.otherCards = kickers;
	}

	public Rank getRank() {
		return manyCards.get(0).getRank();
	}

	public String cards() {
		return manyCards + " " + otherCards;
	}
	
	public int compareTo(Hand hand) {
		int compare = super.compareTo(hand);
		if (compare != 0)
			return compare;
		if (hand instanceof ManyOfAKind) {
			ManyOfAKind many = (ManyOfAKind) hand;
			// compare pair rank
			compare = getRank().compareTo(many.getRank());
			if (compare != 0)
				return compare;
			// same pair, compare kickers
			return compareRanks(otherCards, many.otherCards);
		}
		return compare;
	}

}
